package com.taotao.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.mapper.TbItemParamItemMapper;
import com.taotao.mapper.TbItemParamMapper;
import com.taotao.pojo.TbItemParam;
import com.taotao.pojo.TbItemParamExample;
import com.taotao.pojo.TbItemParamItem;

@Service
public class ItemParamServiceImpl implements ItemParamService {
	@Autowired
	private TbItemParamMapper itemParam;
	
	@Autowired
	private TbItemParamItemMapper itemParamItem;
	
	@Override
	public EUDataGridResult getItemParamList(int page, int rows) {
		TbItemParamExample example = new TbItemParamExample();
		PageHelper.startPage(page, rows);
		List<TbItemParam> list = itemParam.selectByExampleWithBLOBs(example);
		
		
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(list);
		PageInfo<TbItemParam> pageInfo = new PageInfo<TbItemParam>(list); 
		result.setTotal(pageInfo.getTotal());
		return result;
	}

	@Override
	public TaotaoResult checkCatId(int catId) {
		
		if (itemParam.selectByPrimaryKey((long) catId) != null) {
			return TaotaoResult.ok(itemParam.selectByPrimaryKey((long) catId));
		}
		return TaotaoResult.ok();
	}

	@Override
	public TaotaoResult saveItamParam(TbItemParam record) {
		itemParam.insert(record);
		return null;
	}

	@Override
	public TbItemParamItem getItemParamByItemId(long itemId) {
		
		return itemParamItem.selectByPrimaryKey(itemId);
	}

}
